<?php
namespace Blog\Controller;
use Think\Controller;
class LoginController extends Controller 
{
    //登陆
    public function login(){
		if(IS_POST)
		{
    		$param = I('post.');
			$username = $param['username'];
			$pwd = $param['pwd'];
			// $pwd = md5($param['pwd']);
			if(empty($username) || empty($pwd)){
				$this->error('不能为空',U('Login/login'));
			}else{
				$user = M('blog_login');
				$res = $user ->where("username = '$username' and  pwd = '$pwd'")->find();
				if($res){
					cookie('UID',$res['id']);
					$this->success('登录成功',U('Index/index'));
				}else{
					$this->error('输入有误请重新输入',U('Login/login'));
				}
			}
		}else{
			$this->display('login');
		}
	}

	//注册
	public function register(){
		if(IS_POST)
		{
			$param = I('post.');
			$pwd = $param['pwd'];
			$param['pwd'] = $pwd;
			$user = M('blog_login');
			$res = $user->add($param);
			$this->success('注册成功',U('Login/login'));
		}else{
			$this->display('register');
		}
	}
}